< previous page page_661 next page >

Page 661
Remember that pessimistic locking locks the data page as soon as a user begins an edit operation on a record. This lock prevents anyone else from accessing any records on the data page until the first instance releases the record by using Update or UpdateCancel. Now click the error message box and then click the Update button to release the record and unlock the data page.
Now you test the behavior of Microsoft Jet during optimistic locking. Select the Optimistic radio button on both forms. In the first form, click Edit and enter 1 when prompted. The first instance now is editing record 1. Move to the second instance and click Edit. This time, you do not see an error message. When prompted, enter 1 as the record to edit. Again, you see no error message as Microsoft Jet allows you to begin editing record 1 of the set. Now both programs are editing record 1 of the set.
Click the Update button of the second instance of the program to save the new data to the dataset. The second instance now has read, edited, and updated the same record opened earlier by the first instance. Now move to the first instance and click the Update button to save the changes made by this instance. You'll see Error 3197, which tells you that data has been changed and that the update has been canceled. (See Figure 17.7.)
0661-01.jpg
Figure 17.7.
A failed attempt to update during optimistic locking.
Optimistic locking occurs at the moment the Update method is invoked. Under the optimistic scheme, a user can read and edit any record he or she chooses. When the user attempts to write the record back out to disk, the program checks to see whether the original record was updated by any other program since the user's version last read the record. If changes were saved by another program, error 3197 is reported.

 
< previous page page_661 next page >

If you like this book, buy it!